﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/*
    2012-2-17 David检查正常
 */
namespace Benefit.Models.Sys
{
    /// <summary>
    /// 账户表(Server中的虚拟账户)
    /// </summary>
    public class Account
    {
        /// <summary>
        /// 编号
        /// </summary>
        public int Id { get; set; }
        /// <summary>
        /// 账户名
        /// </summary>
        public string AccountName { get; set; }
        /// <summary>
        /// 是否被删除
        /// </summary>
        public bool IsDeleted { get; set; }
        /// <summary>
        /// 删除时间
        /// </summary>
        public DateTime DeletedTime { get; set; }

        ///// <summary>
        ///// 从Server中发现新的账号并临时保存
        ///// </summary>
        ///// <param name="loginAccount">Server中的登录名</param>
        //public void InsertIntoBenefitFromServer(string loginAccount)
        //{
        //    using (DB.DBManager db = new DB.DBManager())
        //    {
        //        Sys.Account account = new Sys.Account();
        //        account.AccountName = loginAccount;
        //        account.IsDeleted = false;
        //        account.DeletedTime = DateTime.Now;
        //        db.Accounts.Add(account);
        //        db.SaveChanges();
        //        db.Dispose();
        //    }
        //}
        ///// <summary>
        ///// 获取所有分析系统的账号
        ///// </summary>
        ///// <returns></returns>
        //public List<Account> GetList()
        //{
        //    using (DB.DBManager db = new DB.DBManager())
        //    {
        //        var query = db.Accounts.ToList();
        //        db.Dispose();
        //        return query;
        //    }
        //}
        ///// <summary>
        ///// 获取所有分析系统未被删除的账号
        ///// </summary>
        ///// <returns></returns>
        //public List<Account> GetUnDeleteList(DB.DBManager db)
        //{
        //    var query = db.Accounts.Where(a => a.IsDeleted == false).ToList();
        //    return query;
        //}
        ///// <summary>
        ///// 根据账户名得到账户编号
        ///// </summary>
        ///// <param name="accountName"></param>
        ///// <returns></returns>
        //public int GetAccountId(string accountName)
        //{
        //    using (DB.DBManager db = new DB.DBManager())
        //    {
        //        int id = -1;
        //        var query = from t in db.Accounts where t.AccountName.Equals(accountName) select t;
        //        if (query.Count() > 0)
        //        {
        //            id = query.First().Id;
        //        }
        //        db.Dispose();
        //        return id;
        //    }
        //}



        ///// <summary>
        ///// 找到某日同一个批次交易员的所有账号
        ///// </summary>
        ///// <param name="Batch"></param>
        ///// <returns></returns>
        //public List<Sys.Account> GetBatchAccounts(int batch, int tradeHistoryId)
        //{
        //    using (DB.DBManager db = new DB.DBManager())
        //    {
        //        List<Operator> operators = new Operator().GetBatchOperators(batch, db);
        //        db.Dispose();
        //        return GetOperatorsAccount(operators, tradeHistoryId);
        //    }
        //}

        ///// <summary>
        ///// 得到一些交易员的所有账号
        ///// </summary>
        ///// <param name="operators"></param>
        ///// <returns></returns>
        //public List<Sys.Account> GetOperatorsAccount(List<Sys.Operator> operators, int tradeHistoryId)
        //{
        //    using (DB.DBManager db = new DB.DBManager())
        //    {
        //        DateTime _pdate = new TradeHistory().GetDateTimeFromTradeHistoryId(tradeHistoryId, db);
        //        List<Sys.Account> accounts = new List<Account>();
        //        foreach (Sys.Operator ops in operators)
        //        {
        //            List<Sys.Account> accs = new Sys.DayOperatorAccount().GetDayOperatorAccounts(_pdate, ops.Id, db);
        //            foreach (Sys.Account a in accs)
        //            {
        //                accounts.Add(a);
        //            }
        //        }
        //        db.Dispose();
        //        return accounts;
        //    }
        //}

        ///// <summary>
        ///// 判断账号在某个月中是否变换过所有者
        ///// </summary>
        ///// <param name="year"></param>
        ///// <param name="month"></param>
        ///// <param name="accountid"></param>
        ///// <returns></returns>
        //public bool HasChangedOwnerInMonth(int year, int month, int accountid)
        //{
        //    using (DB.DBManager db = new DB.DBManager())
        //    {
        //        bool hasChanged = false;
        //        for (int i = 1; i < 6; i++)
        //        {
        //            hasChanged = HasChangedOwnerInWeek(year, month, i, accountid);
        //            if (hasChanged == true)
        //            {
        //                break;
        //            }
        //        }
        //        db.Dispose();
        //        return hasChanged;
        //    }
        //}
        ///// <summary>
        ///// 判断账号在一年中是否变换过所有者
        ///// </summary>
        ///// <param name="year"></param>
        ///// <param name="accountid"></param>
        ///// <returns></returns>
        //public bool HasChangedOwnerInYear(int year, int accountid)
        //{
        //    using (DB.DBManager db = new DB.DBManager())
        //    {
        //        bool hasChanged = false;
        //        for (int i = 1; i < 13; i++)
        //        {
        //            hasChanged = HasChangedOwnerInMonth(year, i, accountid);
        //            if (hasChanged == true)
        //            {
        //                break;
        //            }
        //        }
        //        db.Dispose();
        //        return hasChanged;
        //    }
        //}
        ///// <summary>
        ///// 判断账号在一周中是否变换过所有者
        ///// </summary>
        ///// <param name="year"></param>
        ///// <param name="month"></param>
        ///// <param name="week"></param>
        ///// <param name="accountid"></param>
        ///// <returns></returns>
        //public bool HasChangedOwnerInWeek(int year, int month, int week, int accountid)
        //{
        //    using (DB.DBManager db = new DB.DBManager())
        //    {
        //        bool hasChanged = false;
        //        Sys.TradeHistory th = new TradeHistory();
        //        List<int> operatorids = new List<int>();
        //        var query = db.DayOperatorAccounts.Where(a => a.AccountId == accountid).Where(a => a.Pdate.Year == year).Where(a => a.Pdate.Month == month).ToList();
        //        foreach (Sys.DayOperatorAccount account in query)
        //        {
        //            int _week = th.WeekOfYear(account.Pdate);
        //            if (_week == week)
        //            {
        //                if (operatorids.Count == 0)
        //                {
        //                    operatorids.Add(account.OperatorId);
        //                }
        //                else
        //                {
        //                    var _query = operatorids.Where(a => a == account.OperatorId);
        //                    if (_query.Count() == 0)
        //                    {
        //                        hasChanged = true;
        //                        break;
        //                    }
        //                }
        //            }
        //        }
        //        db.Dispose();
        //        return hasChanged;
        //    }
        //}
    }
}